package com.ocom.mqsimple.controller;

import com.ocom.common.constant.MqSimpleApiUrl;
import com.ocom.common.request.simple.FaceCheckRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mqsimple.business.facecheck.FaceCheckProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/8/16
 **/
@Slf4j
@RestController
public class FaceCheckController {

	@Value("${save.path}")
	String path;

	@Value("${lib.path}")
	String libPath;

	@Autowired
	FaceCheckProductService faceCheckProductService;

	@PostMapping(MqSimpleApiUrl.URL_faceCheck)
	public Result faceCheckMq(@RequestBody FaceCheckRequest faceCheckRequest){
//		log.info("人脸检测开始,【{}】",faceCheckRequest);
//		faceCheckProductService.handle(JSON.toJSONString(faceCheckRequest));
		return ResultUtil.success();
	}


	@PostMapping(MqSimpleApiUrl.URL_faceCheckOnline)
	public Result faceCheckOnline(String url){
//		log.info("人脸在线实时检测开始,【{}】",url);
//		String fileName = (url.split("/"))[url.split("/").length-1];
//		String filePath = path + RandomUtil.getRandomString(10) + fileName;
//
//		boolean b =false;
//		try {
//			File pic = DownloadFileUtils.downloadFile(url, filePath);
//
//			if(pic==null){
////				System.out.println("下载文件失败 返回默认成功" );
//				b = true;
//			}else{
////				System.out.println("下载文件結果" + pic);
//				FaceEngineV41 hrFaceEngine = new FaceEngineV41();
//				b = hrFaceEngine.check(pic,libPath);
//			}
//
//		} catch (Exception e) {
//			log.info("人脸检测处理失败{{}}", e);
//		} finally {
//			try {
//				new File(filePath).delete();
//			} catch (Exception e) {
//				log.error("照片检测 删除失败:【{}】", e);
//			}
//		}
//		if(!b){
//			return ResultUtil.error(ResultEnum.Err_3083);
//		}
		return ResultUtil.success();
	}
}
